﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using UIShare;
using EFong.View.Proxy;
using EFong.Contract;
using DevExpress.XtraExport;
using DevExpress.XtraGrid.Export;

namespace EFong.View.Report
{
    public partial class Frm_月结对账单 : BasicForm
    {
        private Proxy.ReportServiceProxy _reportProxy {get{ return Proxy.ReportServiceProxy.GetInstance();}}
        private Proxy.MasterServiceProxy _masterProxy {get{ return Proxy.MasterServiceProxy.GetInstance();}}

        public Frm_月结对账单()
        {
            InitializeComponent();
        }

        protected override void InitFields()
        {
        }

        protected override void LoadDatas()
        {
            this.bds_Customer.BindingData(_masterProxy.GetAllCustomer().ReturnValue);
            this.dte_StartDate.DateTime = DateTime.Now;
            this.dte_EndDate.DateTime = DateTime.Now.AddMonths(1);
        }

        protected override void Events()
        {
            this.btn_Search.Click += (s, e) =>
            {
                var result = _reportProxy.GetReport06(this.cmb_Customer.GetValue() as RCustomer, this.dte_StartDate.DateTime , this.dte_EndDate.DateTime);
                if(!result.IsSuccess)
                    return;
                List<飞机票月结对账单> list1 = result.ReturnValue;

                bool sourceIsNull = list1 == null;
                bool sourceIsEmpty = !sourceIsNull && list1.Count == 0;

                if (!sourceIsEmpty)
                {
                    this.grd_Flight.DataSource = list1;
                    //this.tabFlight.Show();
                }
                else
                {
                    //this.tabFlight.Hide();
                }

                List<火车票月结对账单> list2 = _reportProxy.GetReport07(this.cmb_Customer.GetValue() as RCustomer, this.dte_StartDate.DateTime).ReturnValue;

                sourceIsNull = list2 == null;
                sourceIsEmpty = !sourceIsNull && list2.Count == 0;

                if (!sourceIsEmpty)
                {
                    this.grd_Train.DataSource = list2;
                    //this.tabTrain.Show();
                }
                else
                {
                    //this.tabTrain.Hide();
                }

                List<酒店月结对账单> list3 = _reportProxy.GetReport08(this.cmb_Customer.GetValue() as RCustomer, this.dte_StartDate.DateTime).ReturnValue;

                sourceIsNull = list3 == null;
                sourceIsEmpty = !sourceIsNull && list3.Count == 0;

                if (!sourceIsEmpty)
                {
                    this.grd_Hotel.DataSource = list3;
                    //this.tabHotel.Show();
                }
                else
                {
                    //this.tabHotel.Hide();
                }

                List<其他项目月结对账单> list4 = _reportProxy.GetReport09(this.cmb_Customer.GetValue() as RCustomer, this.dte_StartDate.DateTime).ReturnValue;

                sourceIsNull = list4 == null;
                sourceIsEmpty = !sourceIsNull && list4.Count == 0;

                if (!sourceIsEmpty)
                {
                    this.grd_Other.DataSource = list4;
                    //this.tabOther.Show
                }
                else
                {
                    //this.tabOther.Hide();
                }
            };
        }


        private void bar_Main_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            switch (e.Item.Name)
            {
                case "bbt_Export":
                    this.export();
                    break;
                case "bbt_Close":
                    this.Close();
                    break;
                default:
                    break;
            }
        }

        private void export()
        {
            switch (tcReport.SelectedTabPageIndex)
            {
                case 0:
                    FileExport.ExportToExcel(this.grd_Flight, "出单统计");
                    break;
                case 1:
                    FileExport.ExportToExcel(this.grd_Train, "出单统计");
                    break;
                case 2:
                    FileExport.ExportToExcel(this.grd_Hotel, "出单统计");
                    break;
                case 3:
                    FileExport.ExportToExcel(this.grd_Other, "出单统计");
                    break;
                //case 4:
                //    FileExport.ExportToExcel(this.grd_TourParty, "出单统计");
                //    break;
                default:
                    break;
            }
        }
    }
}
